package edu.usc.cmb.iregulome.client;

import java.io.File;
import java.util.List;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import edu.usc.cmb.iregulome.job.AnnotationDownloadJob;
import edu.usc.cmb.iregulome.thread.ThreadManager;
import edu.usc.cmb.iregulome.util.NCBIContentUtil;

public class MainApp {

	public static String FILE_BASE_PATH = System.getProperty("user.home")
			+ File.separator + "NCBI" + File.separator;

	public static ApplicationContext ctx;
	
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		try {

			ctx = new ClassPathXmlApplicationContext(
					"context.xml");

			prepareDir();

			// start 3 annotation download thread
			ThreadManager.startAnnotationDownloadService(15);

			// use web service get the uid;

			List<String> sampleIds = NCBIContentUtil
					.extractSampleIdsFromSampleList();

			System.out.println("The total size is " + sampleIds.size());
			for (String sampleId : sampleIds) {
				AnnotationDownloadJob.addId(sampleId);
			}

		} catch (Exception e) {
			e.printStackTrace();
			// TODO: handle exception
		}

	}

	private static void prepareDir() {
		File baseDir = new File(FILE_BASE_PATH);
		if (!baseDir.exists()) {
			baseDir.mkdirs();
		}
	}
}
